package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.StockMaster;
import com.sevattal.service.leaves.entity.vo.StockMasterVo;
import com.sevattal.service.leaves.service.StockMasterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 库存表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "库存信息")
@RestController
@RequestMapping("/admin/leaves/stock-master")
public class StockMasterController {

    @Autowired
    private StockMasterService stockMasterService;

    @ApiOperation("新增库存条目")
    @PostMapping("createStockMaster")
    public R createStockMaster(@ApiParam(value = "库存条目对象",required = true) @RequestBody StockMaster stockMaster){
        boolean result = stockMasterService.createStockMaster(stockMaster);
        if (result){
            return R.ok().message("新增库存信息成功");
        }else {
            return R.error().message("新增库存信息失败");
        }
    }

    @ApiOperation("更新库存条目")
    @PutMapping("updateStockMaster")
    public R updateStockMaster(@ApiParam(value = "库存条目对象",required = true) @RequestBody StockMaster stockMaster){
        boolean result = stockMasterService.updateStockMaster(stockMaster);
        if (result){
            return R.ok().message("更新库存信息成功");
        }else {
            return R.error().message("更新库存信息失败");
        }
    }

    @ApiOperation("删除库存条目")
    @DeleteMapping("deleteStockMaster/{whid}/{mid}")
    public R deleteStockMaster(@ApiParam(value = "仓库ID",required = true) @PathVariable String whid,
                               @ApiParam(value = "物资ID",required = true) @PathVariable String mid){
        boolean result = stockMasterService.deleteStockMaster(whid,mid);
        if (result){
            return R.ok().message("删除库存信息成功");
        }else {
            return R.error().message("删除库存信息失败");
        }
    }

    @ApiOperation("获取库存列表")
    @PostMapping("getStockMasterList")
    public R getStockMasterList(@ApiParam(value = "库存条目对象",required = true) @RequestBody StockMasterVo stockMaster){
        List<StockMasterVo> stockMasterVoList = stockMasterService.getStockMasterList(stockMaster);
        return R.ok().data("stockMasterList", stockMasterVoList);
    }


}

